package com.example.service;

import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName RabbitServiceImpl
 * @Description
 * @Author Yin
 * @Date 2021/4/12 13:49
 * @Version 1.0
 */
@Service
public class RabbitServiceImpl implements RabbitService, RabbitTemplate.ConfirmCallback {
    @Autowired
    private RabbitTemplate rabbitTemplate;


    @Override
    public void sendMsg(String msg) {
        rabbitTemplate.setConfirmCallback(this);
        System.out.println("消息传入");
        rabbitTemplate.convertAndSend("test_queue",msg);
    }

    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String s) {
        if(ack){
            System.out.println("消息消费成功");
        }else{
            System.out.println("消息消费失败");
        }
    }
}
